package com.lbs.jiepiaisi.biz;

import android.content.Intent;

import com.lbs.jiepiaisi.manager.App;
import com.lbs.jiepiaisi.utils.Constant;
import com.lbs.jiepiaisi.utils.HttpUtil;
import com.lbs.jiepiaisi.utils.UrlUtil;

import org.json.JSONObject;

import okhttp3.FormBody;
import okhttp3.Response;

/**
 * 时间：2018/1/23 09:42
 * 作用：接受工单
 */

public class WorkHomeOrderBiz {

    public void finishgetOrderBiz(String wJson, final String flag) {

        FormBody formBody = new FormBody
                .Builder()
                .add("str", wJson)//工单ID
                .build();
        HttpUtil.getHttpUtil().post(UrlUtil.HOME_WORK_ORDER_UPDATE_FLAG, formBody, new HttpUtil.Listener() {
            @Override
            public void success(Response response) {
                Intent intent = new Intent(flag);
                try {
                    //返回结果
                    String jsonString = response.body().string();
                    JSONObject jsonObject = new JSONObject(jsonString);
                    if("0".equals(jsonObject.getString("status"))){
                        intent.putExtra(Constant.KEY_DATA, Constant.STATUS_OK);
                    }else {
                        intent.putExtra(Constant.KEY_DATA, Constant.STATUS_NETWORK_ERROR);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    App.instance.sendBroadcast(intent);
                }
            }

            @Override
            public void failed() {
                Intent intent = new Intent(flag);
                intent.putExtra(Constant.KEY_DATA, Constant.STATUS_NETWORK_ERROR);
                App.instance.sendBroadcast(intent);
            }

            @Override
            public void noNetwork() {
                Intent intent = new Intent(flag);
                intent.putExtra(Constant.KEY_DATA, Constant.STATUS_NO_NET);
                App.instance.sendBroadcast(intent);
            }
        });
    }
}
